package com.guigu.controller.design;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.guigu.pojo.design.DFile;
import com.guigu.pojo.design.DModule;
import com.guigu.pojo.stock.SysUsers;
import com.guigu.service.design.DFileService;
import com.guigu.utils.CodeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-06
 */
@Controller
@RequestMapping("/d-file")
public class DFileController {

    @Resource
    private DFileService dFileService;

    /*
        产品档案登记
     */
    @GetMapping("/registration")
    public String goRegistration() {
        return "jsp/design/dossier_registration";
    }

    /*
        产品档案查询
     */
    @GetMapping("/archives_query")
    public String goArchivesQuery() {
        return "jsp/design/product_query";
    }

    /*
        产品档案登记复核
     */
    @GetMapping("/archive_review")
    public String goArchivesReview() {
        return "jsp/design/products_archive_review";
    }

    /**
     * 产品档案查询子页面
     */
    @GetMapping("/query_subpage")
    public String goQuerySubpage() {
        return "jsp/design/product_profile_query_subpage";
    }

    //产品档案删除
    @GetMapping("/archives_delete")
    public String goProducArchivesDeleted() {
        return "jsp/design/product_archives_are_deleted";
    }

    //产品档案变更
    @GetMapping("/archives_modification")
    public String goModification() {
        return "jsp/design/product_file_modification_query";
    }

    //档案删除恢复
    @GetMapping("/archives_FileDeleteAndRecovery")
    public String goFileDeleteAndRecovery() {
        return "jsp/design/file_deletion_and_recovery_query";
    }

    //档案永久删除前的查询页面
    @GetMapping("/archives_PermanentDeletionQuery")
    public String goPermanentDeletionQuery() {
        return "jsp/design/Permanent_Deletion _Product_Archives_query";
    }

    //制定物料组成设计单
    @GetMapping("/archives_formulate")
    public String goFormulate() {
        return "jsp/design/formulate_material_query";
    }

    //产品I级分类设置
    @GetMapping("/product_level_I")
    public String goLevelI() {
        return "jsp/design/product_level_I";
    }

    //产品II级分类设置
    @GetMapping("/product_level_II")
    public String goLevelII() {
        return "jsp/design/product_level_II";
    }

    //产品III级分类设置
    @GetMapping("/product_level_III")
    public String goLevelIII() {
        return "jsp/design/product_level_III";
    }

    //产品档次级别设置
    @GetMapping("/product_grade")
    public String goGrade() {
        return "jsp/design/product_grade_level";
    }

    //产品经理设置
    @GetMapping("/product_manager_settings")
    public String goManagerSettings() {
        return "jsp/design/product_manager_settings";
    }

    //产品用途类型设置
    @GetMapping("/product_use_type")
    public String goUseType() {
        return "jsp/design/product_use_type";
    }

    //产品档案登记
    @PostMapping("/insertProduct")
    @ResponseBody
    public Boolean insertProduct(@RequestBody DFile dFile) {
        System.out.println(dFile);
        DFile dFile1 = dFileService.selectFileOrderByDescOne();
        CodeUtils codeUtils = new CodeUtils();
        String productCode = codeUtils.getProductCode(dFile.getFirstKindId(), dFile.getSecondKindId(), dFile.getThirdKindId(), dFile1);
        dFile.setProductId(productCode);
        Boolean b = dFileService.addFile(dFile);
        return b;
    }
    //产品档案查询
    @PostMapping("/initialArchiveTable")
    @ResponseBody
    public PageInfo<DFile> initialArchiveTable(@RequestBody HashMap<String, Object> map) {
        PageInfo<DFile> dFilePage = dFileService.selectFileByPage(map);
        return dFilePage;
    }

    //产品档案复核
    @GetMapping("/Review")
    @ResponseBody
    public Boolean review(HttpServletRequest req) {
        Integer id = StringUtils.isNotBlank(req.getParameter("id")) ? Integer.parseInt(req.getParameter("id")) : null;
        DFile dFile = new DFile();
        dFile.setId(id);
        dFile.setCheckTag("1");
        //从session中获取用户名
        SysUsers user = (SysUsers) req.getSession().getAttribute("user");
        dFile.setRegister(user.getLoginId());
        //设置复核时间
        dFile.setCheckTime(new Date());
        boolean b = dFileService.updateById(dFile);
        return b;
    }

    //产品档案查询
    @GetMapping("/productArchivesQuery")
    public String queryProduct() {
        return "jsp/design/product_archives_query";
    }

    @GetMapping("/formulateDesignComposition")
    public String queryProductSubpage() {
        return "jsp/design/Formulate_design_composition";
    }

    @GetMapping("/initialMaterial")
    @ResponseBody
    public DFile initialMaterial(HttpServletRequest req){
        Integer id = StringUtils.isNotBlank(req.getParameter("id")) ? Integer.parseInt(req.getParameter("id")) : null;
        DFile dFile = dFileService.selectById(id);

        return dFile;
    }

    @GetMapping("/AddMaterial")
    public String addMaterial() {
        return "jsp/design/Add_Material";
    }

    @PostMapping("/initialAddTable")
    @ResponseBody
    public PageInfo<DFile> initialAddTable(@RequestBody HashMap<String, Object> map) {
        PageInfo<DFile> dFilePage = dFileService.selectFileByPage(map);
        return dFilePage;
    }


}

